package com.anjian.bamin.anjiandianzimap.activity;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import android.view.View;
import android.widget.ListView;

import com.aiton.administrator.shane_library.shane.ZjbBaseActivity;
import com.anjian.bamin.anjiandianzimap.MyService;
import com.anjian.bamin.anjiandianzimap.R;
import com.anjian.bamin.anjiandianzimap.adapter.MyXunChaAdapter;
import com.anjian.bamin.anjiandianzimap.model.CompanyInfo;

import java.util.ArrayList;
import java.util.List;

public class XunChaListActivity extends ZjbBaseActivity implements View.OnClickListener {

    private List<CompanyInfo> mCompanyInfoList = new ArrayList<>();

    private MyService.MyBind mMyBind;
    private ArrayList<Long> mill = new ArrayList<>();
    private ServiceConnection conn = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            mMyBind = (MyService.MyBind) service;
            mCompanyInfoList.add(new CompanyInfo("中科达机械设备有限公司", "ZKDJXSBYXGS", "福建省泉州市鲤城区", "2013/04/26", 24.506536, 118.13551));
            mCompanyInfoList.add(new CompanyInfo("久久液压气动配件有限公司", "JJYYQDPJYXGS", "泉州市鲤城区江滨北路滨江花园城B区9号店", "15879653652", 24.506536, 118.13551));
            mCompanyInfoList.add(new CompanyInfo("好利用机械设备有限公司", "HLYJXSBYXGS", "福建省泉州市鲤城区新年南路菜州溪滨巷2号", "13328526669", 24.506536, 118.13551));
            mCompanyInfoList.add(new CompanyInfo("金锦机电设备有限公司", "JJJDSBYXGS", "泉州市鲤城区金龙街道南环路589号三楼", "13659752658", 24.506536, 118.13551));
            Log.e("onServiceConnected ", "onServiceConnected " + mMyBind.getMillisUntilFinished(0));
            mill.add(mMyBind.getMillisUntilFinished(0));
            mill.add(mMyBind.getMillisUntilFinished(1));
            mill.add(mMyBind.getMillisUntilFinished(2));
            mill.add(mMyBind.getMillisUntilFinished(3));
            mMyXunChaAdapter.notifyDataSetChanged();
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {

        }
    };
    private MyXunChaAdapter mMyXunChaAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_xun_cha_list);
        init();
    }

    @Override
    protected void initSP() {

    }

    @Override
    protected void initIntent() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void findID() {
        ListView xunChaList = (ListView) findViewById(R.id.xunChaList);
        mMyXunChaAdapter = new MyXunChaAdapter(this,mCompanyInfoList,mill);
        xunChaList.setAdapter(mMyXunChaAdapter);
    }

    @Override
    protected void initViews() {

    }

    @Override
    protected void setListeners() {
        findViewById(R.id.imgBack).setOnClickListener(this);
        mMyXunChaAdapter.setOnCompanyClickListener(new MyXunChaAdapter.OnCompanyClickListener() {
            @Override
            public void onCompanyClick(CompanyInfo companyInfo) {
                Intent intent = XunChaActivity.newIntent(XunChaListActivity.this, companyInfo);
                startActivityTo(intent);
            }
        });
    }



    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.imgBack:
                finishTo();
                break;
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        Intent server = new Intent();
        server.setClass(XunChaListActivity.this, MyService.class);
        bindService(server, conn, Context.BIND_AUTO_CREATE);
        startService(server);
    }

    @Override
    protected void onDestroy() {
        unbindService(conn);
        super.onDestroy();
    }
}
